package com.hongxun.budget.ui.dialog;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.hongxun.budget.R;
import com.hongxun.budget.utils.RecyclerViewUtils;
import com.hongxun.interfaces.ResponseListener;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/11/1.
 */

public class BottomClickDialog extends BaseBottomFragmentDialog {


    @BindView(R.id.list)
    RecyclerView list;
    ResponseListener listener;
    List<String> datas = new ArrayList<>();
    SuperAdapter<String> superAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_bottom_click;
    }

    @Override
    protected void initViews() {
        list.setLayoutManager(RecyclerViewUtils.getLinearLayoutManagerForVertical(getActivity()));
        list.setAdapter(superAdapter = new SuperAdapter<String>(R.layout.content_dialog_bottom_click) {
            @Override
            public void bindView(ViewHolder viewHolder, final String s, final int i) {
                Button button = viewHolder.getView(R.id.btn);
                button.setText(s);
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        listener.response(s, i);
                        dismiss();
                    }
                });
            }
        });
        superAdapter.setData(datas);
    }

    public BottomClickDialog setListener(ResponseListener listener) {
        this.listener = listener;
        return this;
    }

    public BottomClickDialog setDatas(List<String> datas) {
        this.datas = datas;
        return this;
    }

    @OnClick(R.id.cancel)
    public void onViewClicked() {
        dismiss();
    }
}
